//
//  AFFVAlertPublic.m
//  AnyfishApp
//
//  Created by Bob Lee on 16/6/7.
//  Copyright © 2016年 Anyfish. All rights reserved.
//

#import "AFFVAlertPublic.h"
#import "UIImage+Orientation.h"
#import "UIFont+AFF.h"

@interface AFFVAlert() {
    blockResult rBlock;
}

@end

@implementation AFFVAlert

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    
    if(self){
    }
    
    return self;
}

- (blockResult)block {
    return rBlock;
}

- (void)actionResult:(blockResult)block {
    rBlock = block;
}

@end






@implementation AFFBtnShare

- (instancetype)initWithOrigin:(CGPoint)point isBorder:(BOOL)border {
    self = [super init];
    if (self) {
        CGRect frame = CGRectMake(point.x, point.y, 60, 61+kSetting.font_11.lineHeightUsed);
        self.frame = frame;
        self.backgroundColor = [UIColor clearColor];
        
        frame = CGRectMake(0, 0, 60, 60);
        UIButton *btn = [[UIButton alloc] initWithFrame:frame];
        btn.layer.cornerRadius = kCorner_Chat_Bubble;
        [self addSubview:btn];
        self.btnIcon = btn;
        
        if (border) {
            btn.layer.borderWidth = 0.5;
            btn.layer.borderColor = kSetting.color_d7d7d7.CGColor;
        }
        
        
        frame = CGRectMake(12, 12, 36, 36);
        UIImageView *imgIcon = [[UIImageView alloc] initWithFrame:frame];
        [btn addSubview:imgIcon];
        self.imgIcon = imgIcon;
        
        frame = CGRectMake(0, 61, 60, kSetting.font_11.lineHeightUsed);
        UILabel *labGroup = [[UILabel alloc]initWithFrame:frame];
        labGroup.textAlignment = kTextAlignmentCenter;
        labGroup.textColor = kSetting.color_333333;
        labGroup.font = [UIFont systemFontOfSize:11];
        [self addSubview:labGroup];
        self.labDes = labGroup;
    }
    return self;
}

@end

@implementation AFFVSheetShare

- (instancetype)initWithArray:(NSArray <NSNumber *>*)arr type:(EShareType)type {
    self = [super init];
    if (self) {
        BOOL border = type == EShare_Normal ? YES:NO;
        self.frame = arr.count > 4 ? CGRectMake(0, 0, SCREEN_WIDTH, border ? (143 + 24 + 61 + kSetting.font_11.lineHeightUsed): (131 + 12 + 61 + kSetting.font_11.lineHeightUsed)) : CGRectMake(0, 0, SCREEN_WIDTH, border ? 143 : 131);
        self.backgroundColor = kSetting.color_ffffff;
        
        CGFloat padding = (arr.count == 1 ? 0 : (SCREEN_WIDTH - (border ? 74 : 50) - 60 *4)/3);
        CGFloat y = arr.count > 4 ? ((border ? 60 : 48) + 61+kSetting.font_11.lineHeightUsed) : (border ? 36 : 24);
        CGPoint point = CGPointMake(37, y);
        
        for (int i = 0; i < arr.count; i ++) {
            NSArray *array = [self getImgNameAndName:arr[i] type:type];
            point.x = (border ? 37 : 25) + (padding + 60) *i;
            AFFBtnShare *btn = [[AFFBtnShare alloc] initWithOrigin:point isBorder:border];
            btn.btnIcon.tag = [arr[i] integerValue];
            [btn.btnIcon addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
            btn.labDes.text = array[0];
            btn.imgIcon.image = [UIImage imageNamed:array[1]];
            [self addSubview:btn];
        }
        
        if (arr.count > 4) {
            CGPoint point1 = CGPointMake(37, 24);
            for (int i = 4; i < arr.count; i ++) {
                NSArray *array = [self getImgNameAndName:arr[i] type:type];
                point1.x = (border ? 37 : 25) + (padding+60) * (i-4);
                point1.y = border ? 36 : 24;
                AFFBtnShare *btn = [[AFFBtnShare alloc] initWithOrigin:point1 isBorder:border];
                btn.btnIcon.tag = [arr[i] integerValue];
                [btn.btnIcon addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
                btn.labDes.text = array[0];
                btn.imgIcon.image = [UIImage imageNamed:array[1]];
                [self addSubview:btn];
            }
        }
    }
    return self;
    
}

- (UIImage *)getImgName:(NSString *)string type:(U32)type{
    NSString *str;

    return  [UIImage imageNamed:str];
}

//1.好友、2.群组、3.朋友圈、4.娱乐圈、5.微信好友、6.微信朋友圈
- (NSArray *)getImgNameAndName:(NSNumber *)number type:(EShareType)type{
    NSArray *arr;
    NSString *strName;
    NSString *strImg;

    return arr;
}

- (void)btnClicked:(UIButton *)btn {
    if(self.block){
        self.block(btn.tag, nil);
    }
}

@end

@implementation AFFVAlertCount {
    UILabel *labCount;
    U32 start, end;
}

- (id)initWithCount:(U32)count {
    return [self initWithCount:count isDown:YES max:0];
}

- (id)initWithCount:(U32)count isDown:(BOOL)isDown max:(U32)max {
    self = [super init];
    if(self){
        start = count;
        end = isDown ? 0 : max;
        //
        CGFloat width = 50;
        CGFloat padding = 30;
        CGRect frame = CGRectMake(0, 0, width+padding*2, width+padding*2);
        self.frame = frame;
        
        UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(padding, padding, width, width)];
        lab.font = [UIFont fontWithSize_S:30];
        lab.textColor = kSetting.color_ffffff;
        lab.textAlignment = kTextAlignmentCenter;
        labCount = lab;
        [self addSubview:lab];
    }
    
    return self;
}

- (void)startCount {
  
    
}

@end



